#ifndef QABSTRACTHOST_H
#define QABSTRACTHOST_H

#include "objects_global.h"
#include "qhostfactory.h"

#include <QObject>
#include <QMap>
#include <QAction>

#define HOST_TYPE      "host_type"

class QAbstractProperty;
class XMLObject;

class OBJECTS_SHARED_EXPORT QAbstractHost : public QObject
{
    Q_OBJECT
public:
    explicit QAbstractHost(QAbstractHost *parent = 0);
    ~QAbstractHost();

    void    insert_children(const QList<int> &indexs,const QList<QAbstractHost*> &children);
    void    remove_children(const QList<QAbstractHost*> &children);
    void    set_parent(QAbstractHost* parent,int index);
    void    clear();


    QList<QAbstractHost*>   get_children();
    QAbstractHost*          get_child(int index);
    QAbstractHost*          get_parent();
    int                     get_child_count();

    QList<QAbstractProperty*>   get_propertys();
    QAbstractProperty*          get_property(const QString &name);
    QVariant                    get_property_value(const QString &name);
    void                        set_property_value(const QString &name,const QVariant &value);

    void                    set_attribute(const QString& key,const QString& value);
    QString                 get_attribute(const QString& key);

    void                    set_default();

    static QString          get_show_name();
    static QString          get_show_icon();
    static QString          get_show_group();
    static QString          get_object_type();

    QList<QAction*>         get_actions();
    QAction*                get_action(const QString& name);
    void                    insert_action(const QString& name,QAction* ac,int index=-1);
    void                    remove_action(const QString& name);

    QObject*                get_object();
    void                    init();

    void                    to_object(XMLObject* xml);
    void                    from_object(XMLObject* xml);

    QString                 get_uuid();
    void                    set_uuid(const QString& uuid);
protected:
    virtual void            create_object();
    virtual void            init_property();

    void                    insert_property(QAbstractProperty* property,int index=-1);
    void                    remove_property(const QString &name);

    void                    exec(const QString &code,const QMap<QString,QString> &param);
signals:
    void                    insert_children_signal(const QList<QAbstractHost*> &host,const QList<int> &index);
    void                    remove_children_signal(const QList<QAbstractHost*> &host);
    void                    parent_changed();
public slots:
protected:
    QList<QAbstractHost*>               m_children;
    QAbstractHost*                      m_parent;
    QList<QAbstractProperty*>           m_propertys;
    QMap<QString,QAbstractProperty*>    m_nameToProperty;
    QList<QAction*>                     m_actions;
    QMap<QString,QAction*>              m_nameToAction;
    QObject*                            m_object;
    QMap<QString,QString>               m_attributes;
};

#endif // QABSTRACTHOST_H
